package com.xxkj.nmip.bean;


import androidx.annotation.NonNull;

import com.google.gson.Gson;

import java.io.Serializable;
import java.util.Date;

import com.xxkj.nmip.js.JsCodeType;

public class JsResBean implements JsCodeType, Serializable {
    public int code = 200;
    public String msg = "成功";
    public Object data;

    public JsResBean() {
    }

    public JsResBean(Object data) {
        this.data = data;
    }

    public JsResBean(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public JsResBean(int code, Object data) {
        this.code = code;
        this.data = data;
        switch (code) {
            case SUCCESS:
                this.msg = "获取成功";
                break;
            case FAIL:
                this.msg = "获取信息失败";
                break;
            case NO_PERMISSION:
                this.msg = "无访问权限";
                break;
            case NOT_LOGIN:
                this.msg = "用户未登录";
                break;
            case NOT_METHOD:
                this.msg = "方法未实现";
                break;
            case PARAMETER_ERROR:
                this.msg = "参数返回失败";
                break;
        }
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @NonNull
    @Override
    public String toString() {
        try {
            long s = new Date().getTime();
            String json = new Gson().toJson(this);
            return json;
        } catch (Exception e) {
            return "";
        }
    }

}
